﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Threading;

namespace UniTAC
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Mutex mt = null;

            try
            {
                mt = Mutex.OpenExisting("UniTAC");
            }
            catch (WaitHandleCannotBeOpenedException)
            {

            }

            if (mt == null)
            {
                //If the mutex doesn't exist create it and launch the application.
                mt = new Mutex(true, "UniTAC");
                Application.Run(new StartWindow());

                //Tell GC not to destroy mutex until the application is running and
                //release the mutex when application exits.
                GC.KeepAlive(mt);
                mt.ReleaseMutex();
            }
            else
            {
                //The mutex existed so exit
                mt.Close();
                MessageBox.Show("Application already running");
                Application.Exit();
            }
        }
    }
}
